import sys

from IndexWindowUi import dispalyIndexWindow
from commonDaoApi.impl.AppInfoDao import AInfoDao
from commonFactory.impl.TtzFactoryLogin import TTZFactoryLogin
from commonInfo.TtzInfo import TTZInfo
from commonServiceApi.impl.TtzLoginImpl import TTZLoginImpl
import easygui
def submit_form(loginWindow,platform_var,phone_var,password_entry):
    password = password_entry.get()
    platform = platform_var.get()
    phone = phone_var.get()
    print("platform:",platform,"phone:",phone,"password:",password)
    loginVO = None
    appInfoMap = AInfoDao().queryAllAppInfo()
    try:
        if platform == "探探鼠":
            loginVO = TTZFactoryLogin().createBaseLogin(TTZInfo(),phone,password)
            loginVO = TTZLoginImpl().login(loginVO)

        # 设置appId 更新需要
        loginVO.appId = appInfoMap.get(platform)


        # 登录失败的情况
        if loginVO is None:
            easygui.msgbox(f"{loginVO.bInfo} {loginVO.userPhone} 用户登录失败,请联系管理员 18340057070 ")

        answer = easygui.buttonbox(f"{loginVO.bInfo} {loginVO.userPhone} 用户登录成功,", choices=["是", "否"])
        if answer == "是":
            loginWindow.destroy() # 销毁登录窗口
            dispalyIndexWindow(loginVO) # 显示首页窗口
        else:
            sys.exit()
            loginWindow.destroy()
    except Exception as e:
        # traceback.print_exc()
        print("异常信息:", e)